/**
* \brief 
* \author pengcheng (pengcheng@yslrpch@126.com)
* \date 2020-05-30
* \attention CopyrightÃ‚Â©ADC Technology(tianjin)Co.Ltd
* \attention Refer to COPYRIGHT.txt for complete terms of copyright notice
*/

#include <numeric>
#include <string>
#include <vector>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/shared_lock_guard.hpp>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/message.h>
#include <google/protobuf/text_format.h>
#ifndef _UTILS_H___
#define _UTILS_H___

namespace detection
{
class ProtoHelpFun
{
public:

    typedef google::protobuf::Message Message;
    typedef google::protobuf::io::FileInputStream FileInputStream;
    typedef google::protobuf::io::FileOutputStream FileOutputStream;
    typedef google::protobuf::io::ZeroCopyInputStream ZeroCopyInputStream;
    typedef google::protobuf::io::CodedInputStream CodedInputStream;
    typedef google::protobuf::io::ZeroCopyOutputStream ZeroCopyOutputStream;
    typedef google::protobuf::io::CodedOutputStream CodedOutputStream;

    static const uint32_t kProtoReadBytesLimit = std::numeric_limits<uint32_t>::max();
    static const uint32_t kProtoReadBytesWarningThreshold = 536870912; //512MB

    static void ReadProtoFromTextFile(const std::string &filename, Message *proto);
    static void ReadProtoFromBinaryFile(const std::string &filename, Message *proto);
};

/// Parse string in protobuf according to delimminator, and convert into a vector
template<typename T>
std::vector<T> ParseStringAsVec(const std::string& input,
                                const std::string& delim)
{
	std::vector<T> output;
	std::vector<std::string> dst;
	boost::split(dst, input, boost::is_any_of(delim), boost::token_compress_on);
	for (auto& it : dst)
	{
		output.push_back(boost::lexical_cast<T>(it));
	}
	return output;
}
}
#endif